import type {
  CreateAxiosDefaults,
  InternalAxiosRequestConfig,
  AxiosResponse,
  AxiosRequestConfig,
  AxiosRequestHeaders
} from "axios"
import { type LoadingOptions } from "@/utils/Feedback"

export interface Interceptors {
  requestInterceptor?: (config: InternalAxiosRequestConfig) => InternalAxiosRequestConfig
  requestInterceptorCatch?: (error: any) => any
  responseInterceptor?: (config: AxiosResponse) => AxiosResponse
  responseInterceptorCatch?: (error: any) => any
}

export interface IRewriteCreateAxiosDefaults extends CreateAxiosDefaults {
  interceptors?: Interceptors
  isShowLoading?: boolean // 实例是否开始loading，默认true
  loadingOptions?: LoadingOptions
}

export interface IRewriteAxiosRequestConfig extends Omit<AxiosRequestConfig, "header"> {
  interceptors?: Omit<Interceptors, "requestInterceptorCatch" | "rresponseInterceptorCatch">
  isCustomLoading?: boolean // 单独请求是否开启自定义loading
  loadingOptions?: LoadingOptions
  headers: AxiosRequestHeaders
  contentType?: AxiosHeaders
}

export type AxiosHeaders = "application/json" | "application/x-www-form-urlencoded" | "multipart/form-data"

export type AxiosMethod = "get" | "post" | "delete" | "put" | "GET" | "POST" | "DELETE" | "PUT"

export type AxiosResponseType = "arraybuffer" | "blob" | "document" | "json" | "text" | "stream"

export interface AxiosConfig {
  params?: any
  data?: any
  url?: string
  method?: AxiosMethod
  headersType?: string
  responseType?: AxiosResponseType
}

export interface IResponse<T = any> {
  code: string
  data: T extends any ? T : T & any
}

export interface PageParam {
  pageSize?: number
  pageNo?: number
}
